/**
 * Collection lists
 * -- masterdata_regions
 * -- masterdata_dictionaries
 * -- masterdata_userportraits
 * -- masterData_actions
 * -- masterData_roleActions
 */

var Schema = mongoose.Schema;

//=================================masterdata_regions=======================================
var regionMongoSchema = new Schema({
    type: {type: String, enum: ['country', 'province', 'city', 'county']},    //类型
    areaCode: String,                                                               //地区代码
    name: String,                                           //名称
    pinyin: String,
    cultureCode: {type: String, enum: ['zh-CN', 'en-GB']},                     //语言代码
    parentId: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},     //父亲记录
    dateLastModified: {type: Date, default: Date.now},                          //最后修改日期
    lastModifiedBy: {type: Schema.Types.ObjectId, ref: 'user'},             //修改人
    versionNo: String                                                              //版本号
});

mongoose.model('masterData_Regions', regionMongoSchema, 'masterdata_regions');

var regionUserMongoSchema = new Schema({
    type: {type: String, enum: ['country', 'province', 'city', 'county']},    //类型
    areaCode: String,                                                               //地区代码
    name: String,                                           //名称
    pinyin: String,
    cultureCode: {type: String, enum: ['zh-CN', 'en-GB']},                     //语言代码
    parentId: {type: Schema.Types.ObjectId, ref: 'masterData_Regions'},     //父亲记录
    dateLastModified: {type: Date, default: Date.now},                          //最后修改日期
    lastModifiedBy: {type: Schema.Types.ObjectId, ref: 'user'},             //修改人
    versionNo: String                                                              //版本号
});

mongoose.model('masterData_Regions_user', regionUserMongoSchema, 'masterdata_regions_user');

var regionjdMongoSchema = new Schema({
    type: String,
    parentCode: Number,
    code: {type: Number, unique: true},
    name: String,
    dateCreated: {type: Date, default: Date.now}
});

mongoose.model('masterData_Regions_jd', regionjdMongoSchema, 'masterdata_regions_jd');


//==========================masterdata_dictionaries========================================
var dataDictionary = new Schema({
    category: {type: String, enum: ['01', '02', '03']},  //01 - hobby, 02 - 标签, 03 -商户类别
    value: String,
    level: Number,                                       //1,热门
    imageURL: String,
    defaultURL: String,
    dateLastModified: {type: Date, default: Date.now},
    displayOrder: Number,
    versionNo: String
});
mongoose.model('masterData_Dictionaries', dataDictionary, 'masterdata_dictionaries');


//==============================masterdata_userportraits=====================================
var userPortraitSchema = new Schema({
    value: String,
    gender: {type: String, enum: ['男', '女']},
    portraitURL: String,
    displayOrder: Number,
    dateCreated: {type: Date, default: Date.now},
    hobby: {type: Schema.Types.ObjectId, ref: 'masterData_Dictionaries'}    //关联到兴趣爱好的schema ID
});
mongoose.model('masterData_UserPortrait', userPortraitSchema, 'masterdata_userportraits');


//===========================================================================================
var actionSchema = new Schema({
    name: String,
    tag: String,
    dateCreated: {type: Date, default: Date.now}
});
mongoose.model('masterData_actions', actionSchema, 'masterData_actions');


//==================================masterData_roleActions==================================
var roleActionSchema = new Schema({
    role: {type: String, enum: ['normal', 'vip', 'talent']},
    action: {type: Schema.Types.ObjectId, ref: 'masterData_actions'},
    dateCreated: {type: Date, default: Date.now}
});
mongoose.model('masterData_roleActions', roleActionSchema, 'masterData_roleActions');